package center

import (
	"gitee.com/game_diamond/consts"
	"gitee.com/game_diamond/model/room"
	"gitee.com/game_diamond/protocols"
	"gitee.com/game_diamond/server"
	"gitee.com/game_diamond/session"
)

//大厅
func init() {
	server.RegisterWsAction(consts.ActorStudent, consts.ActionStudentClientCenter, StudentCourseListAction)
	server.RegisterWsAction(consts.ActorStudent, consts.ActionStudentClientStartCourse, StartCourseAction)
}

//学生课程列表
func StudentCourseListAction(studentId int, body *protocols.WebSocketBody) {

	//course list

	return
}

//点击上课
func StartCourseAction(studentId int, body *protocols.WebSocketBody) {
	//params
	teacherId, courseId := 0, 0
	courseType := 0

	//global
	gl := session.GetGlobalStudentSession(studentId)
	gl.CourseId = courseId
	gl.Save()

	roomId := room.MakeRoomId(teacherId, gl.ClassId, courseId, consts.RoomTypeNormal)
	_, err := room.FindRoom(roomId)
	if err != nil {
		return
	}
	//enter room
	ss := &room.StudentExecutor{
		StudentId: gl.StudentId,
	}
	switch courseType {
	case 0:
		err = ss.EnterAIRoom(roomId)
		if err != nil {
			return
		}
	}

	return
}
